//
//  ZYPlayerViewController.m
//  YaYa
//
//  Created by 张亚 on 2019/1/11.
//  Copyright © 2019年 张亚. All rights reserved.
//

#import "ZYPlayerViewController.h"
#import "ZYLiveChatViewController.h"

@interface ZYPlayerViewController ()


@property (nonatomic, strong) UIImageView * blurImageView;

@property (nonatomic, strong) UIButton *closeBtn;

@property (nonatomic, strong) ZYLiveChatViewController * liveChatVC;

@end

@implementation ZYPlayerViewController

#pragma mark - lazy
- (ZYLiveChatViewController *)liveChatVC {
    if (_liveChatVC == nil) {
        _liveChatVC = [[ZYLiveChatViewController alloc] init];
        
    }
    return _liveChatVC;
}
- (UIButton *)closeBtn {
    if (_closeBtn == nil) {
        _closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        
        [_closeBtn setImage:[UIImage imageNamed:@"fh"] forState:UIControlStateNormal];
        [_closeBtn sizeToFit];
        _closeBtn.frame = CGRectMake(SCREEN_WIDTH -_closeBtn.width - 10, kStatusBarHeight, _closeBtn.width, _closeBtn.height);
        [_closeBtn addTarget:self action:@selector(closeAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _closeBtn;
}
#pragma mark - life View

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self initUI];
    
    [self addChilderVC];
    UIWindow * playWindow = [[UIApplication sharedApplication].delegate window];
    [playWindow addSubview:self.closeBtn];
}
- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [self.closeBtn removeFromSuperview];
    
}


- (void)initUI {
    self.view.backgroundColor = [UIColor whiteColor];
    
    //毛玻璃效果
    self.blurImageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
    [self.view addSubview:self.blurImageView];
    
    //创建毛玻璃效果
    UIBlurEffect * blur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
    //创建毛玻璃视图
    UIVisualEffectView * vse = [[UIVisualEffectView alloc] initWithEffect:blur];
    vse.frame = self.blurImageView.bounds;
    [self.blurImageView addSubview:vse];
    
    //添加关闭按钮
    
}

- (void)addChilderVC {
    
    [self addChildViewController:self.liveChatVC];
    
    [self.view addSubview:self.liveChatVC.view];
    [self.liveChatVC.view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view);
    }];

    
}


#pragma mark - Action
- (void)closeAction:(UIButton *)button {
    [self dismissViewControllerAnimated:YES completion:nil];
}
@end
